home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1810 / 1810.xpi / chrome / showcase.jar / content / showcaseOverlay.js < prev    next >
Text File  |  2010-01-17  |  11KB  |  298 lines

  1. function showShowcaseAllWindows(event) {
  2.   if ((!event) || (event.type != "command")) {
  3.       showShowcase(true, false);
  4.   } else if (event.shiftKey) {
  5.     if (event.ctrlKey) {
  6.       showShowcase(false, true);
  7.     } else {
  8.       showShowcase(false, false);
  9.     }
  10.   } else {
  11.     if (event.ctrlKey) {
  12.       showShowcase(true, true);
  13.     } else {
  14.       showShowcase(true, false);
  15.     }
  16.   }
  17. }
  18.  
  19. function showShowcaseThisWindow(event) {
  20.   if ((!event) || (event.type != "command")) {
  21.       showShowcase(false, false);
  22.   } else if (event.shiftKey) {
  23.     if (event.ctrlKey) {
  24.       showShowcase(true, true);
  25.     } else {
  26.       showShowcase(true, false);
  27.     }
  28.   } else {
  29.     if (event.ctrlKey) {
  30.       showShowcase(false, true);
  31.     } else {
  32.       showShowcase(false, false);
  33.     }
  34.   }
  35. }
  36.  
  37. function showShowcaseTabAllWindows(event) {
  38.   if ((!event) || (event.type != "command")) {
  39.       showShowcase(true, true);
  40.   } else if (event.shiftKey) {
  41.     if (event.ctrlKey) {
  42.       showShowcase(false, false);
  43.     } else {
  44.       showShowcase(false, true);
  45.     }
  46.   } else {
  47.     if (event.ctrlKey) {
  48.       showShowcase(true, false);
  49.     } else {
  50.       showShowcase(true, true);
  51.     }
  52.   }
  53. }
  54.  
  55. function showShowcaseTabThisWindow(event) {
  56.   if ((!event) || (event.type != "command")) {
  57.       showShowcase(false, true);
  58.   } else if (event.shiftKey) {
  59.     if (event.ctrlKey) {
  60.       showShowcase(true, false);
  61.     } else {
  62.       showShowcase(true, true);
  63.     }
  64.   } else {
  65.     if (event.ctrlKey) {
  66.       showShowcase(false, false);
  67.     } else {
  68.       showShowcase(false, true);
  69.     }
  70.   }
  71. }
  72.  
  73. function showShowcase(allWindows, embedTab) {
  74.       var prefs = Components.classes["@mozilla.org/preferences-service;1"].
  75.                     getService(Components.interfaces.nsIPrefService);
  76.       prefs = prefs.getBranch("extensions.showcase.");
  77.  
  78.       // First close the window so we can keep the "last position" and "last size" values
  79.       if (!embedTab) {
  80.         var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
  81.         var windowIter = wm.getEnumerator('extension:showcase');
  82.         if (windowIter.hasMoreElements()) {
  83.           var targetWindow = windowIter.getNext();
  84.           if (targetWindow.wrappedJSObject) targetWindow = targetWindow.wrappedJSObject;
  85.  
  86.           if (targetWindow) {
  87.             var shouldRefresh = false;
  88.             if (allWindows) {
  89.               if (!targetWindow.globalMode) {
  90.                 targetWindow.globalMode = true;
  91.                 shouldRefresh = true;
  92.               }
  93.             } else {
  94.               if (targetWindow.globalMode) {
  95.                 targetWindow.globalMode = false;
  96.                 targetWindow.localTargetWindow = window;
  97.                 shouldRefresh = true;
  98.               } else {
  99.                 if ((targetWindow.localTargetWindow && (targetWindow.localTargetWindow != window)) || 
  100.                     (!targetWindow.localTargetWindow && (window.opener != window))) {
  101.                   targetWindow.localTargetWindow = window;
  102.                   shouldRefresh = true;
  103.                 }
  104.               }
  105.             }
  106.             if (shouldRefresh)
  107.               targetWindow.refreshScreen();
  108.  
  109.             targetWindow.focus();
  110.             return;
  111.           }
  112.         }
  113.       }
  114.  
  115.     // Check if we've to embed showcase in a tab
  116.     if (embedTab) {
  117.         // Look for any old instance
  118.         var tabbrowser = document.getElementById("content");
  119.         var tabs = tabbrowser.mTabContainer.childNodes;
  120.         var totalTabs = tabs.length;
  121.         var selectedTab = tabbrowser.getBrowserForTab(tabs[tabbrowser.mTabContainer.selectedIndex]);
  122.  
  123.         var found = false;
  124.         for (var j = 0; (j < totalTabs) && !found; j++) {
  125.           var targetTab = tabbrowser.getBrowserForTab(tabs[j]);
  126.           if (targetTab.contentWindow) {
  127.             var targetTabWindow = targetTab.contentWindow;
  128.             if (targetTabWindow.wrappedJSObject) {
  129.               targetTabWindow = targetTabWindow.wrappedJSObject;
  130.             }
  131.             if (targetTabWindow.isShowcaseWindow) {
  132.               found = true;
  133.               if (targetTab == selectedTab) {
  134.                 targetTabWindow.close();
  135.               } else {
  136.                 if (targetTabWindow.globalMode != allWindows) {
  137.                   targetTabWindow.location = "chrome://showcase/content/showcase.xul?global=" + allWindows;
  138.                   //targetTabWindow.globalMode = allWindows;
  139.                   //targetTabWindow.refreshScreen();
  140.                 }
  141.                 tabbrowser.mTabContainer.selectedIndex = j;
  142.                 targetTabWindow.focus();
  143.               }
  144.             }
  145.           }
  146.         }
  147.  
  148.         if (!found) {
  149.           var showcaseTab = getBrowser().addTab("chrome://showcase/content/showcase.xul?global=" + allWindows);
  150.           var initialPosition = prefs.getIntPref("tabInitialPosition");
  151.           var tabbrowser = getBrowser();
  152.           if (initialPosition == 0) {
  153.             // Current position
  154.             
  155.             tabbrowser.moveTabTo(showcaseTab, tabbrowser.selectedTab._tPos);
  156.             
  157.           } else if (initialPosition == 2) {
  158.             // First position
  159.             
  160.             tabbrowser.moveTabTo(showcaseTab, 0);
  161.             
  162.           }
  163.           tabbrowser.selectedTab = showcaseTab;
  164.         }
  165.         return;
  166.     }
  167.  
  168.       var windowHeight, windowWidth;
  169.       var createWindowString = "chrome";
  170.       
  171.       var showcaseWidthType = prefs.getIntPref("windowWidth");
  172.       var widthPercentage = parseFloat(prefs.getCharPref("windowWidthPercentage"));
  173.       var widthModifier = prefs.getIntPref("windowWidthModifier");
  174.  
  175.       createWindowString += ",outerWidth=";
  176.  
  177.       if (showcaseWidthType == 0) {
  178.         var contentArea = getBrowser().mCurrentBrowser;
  179.         windowWidth = Math.floor(contentArea.boxObject.width * widthPercentage / 100 + widthModifier);
  180.         createWindowString += windowWidth;
  181.       } else if (showcaseWidthType == 1) {
  182.         windowWidth = Math.floor(window.screen.availWidth * widthPercentage / 100 + widthModifier);
  183.         createWindowString += windowWidth;
  184.       } else if (showcaseWidthType == 2) {
  185.         windowWidth = prefs.getIntPref("windowLastWidth");
  186.         createWindowString += windowWidth;
  187.         if (windowWidth < 1) {
  188.           windowWidth = 300;
  189.         }
  190.       } else { // if (showcaseWidthType == 3) {
  191.         windowWidth = Math.floor(window.outerWidth * widthPercentage / 100 + widthModifier);
  192.         createWindowString += windowWidth;
  193.       }
  194.  
  195.       var showcaseHeightType = prefs.getIntPref("windowHeight");
  196.       var heightPercentage = parseFloat(prefs.getCharPref("windowHeightPercentage"));
  197.       var heightModifier = prefs.getIntPref("windowHeightModifier");
  198.  
  199.       createWindowString += ",outerHeight=";
  200.  
  201.       if (showcaseHeightType == 0) {
  202.         var contentArea = getBrowser().mCurrentBrowser;
  203.         windowHeight = Math.floor(contentArea.boxObject.height * heightPercentage / 100 + heightModifier);
  204.         createWindowString += windowHeight;
  205.       } else if (showcaseHeightType == 1) {
  206.         windowHeight = Math.floor(window.screen.availHeight * heightPercentage / 100 + heightModifier);
  207.         createWindowString += windowHeight;
  208.       } else if (showcaseHeightType == 2) {
  209.         windowHeight = prefs.getIntPref("windowLastHeight");
  210.         if (windowHeight < 1) {
  211.           windowHeight = 300;
  212.         }
  213.         createWindowString += windowHeight;
  214.       } else { // if (showcaseHeightType == 3) {
  215.         windowHeight = Math.floor(window.outerHeight * heightPercentage / 100 + heightModifier);
  216.         createWindowString += windowHeight;
  217.       }
  218.  
  219.       if (prefs.getBoolPref("windowAttributeDialog")) {
  220.         createWindowString += ",dialog=yes";
  221.       } else {
  222.         createWindowString += ",dialog=no";
  223.       }
  224.  
  225.       if (prefs.getBoolPref("windowAttributeDependent")) {
  226.         createWindowString += ",dependent=yes";
  227.       }
  228.  
  229.       if (!prefs.getBoolPref("windowAttributeTitleBar")) {
  230.         createWindowString += ",titlebar=no";
  231.       }
  232.  
  233.       if (prefs.getBoolPref("windowAttributeModal")) {
  234.         createWindowString += ",modal=yes";
  235.       }
  236.  
  237.       if (prefs.getBoolPref("windowAttributeAlwaysRaised")) {
  238.         createWindowString += ",alwaysRaised=yes";
  239.       }
  240.  
  241.       var showcasePosition = prefs.getIntPref("windowPosition");
  242.       if (showcasePosition == 0) {
  243.         // Center on invoking content area
  244.         var contentArea = getBrowser().mCurrentBrowser;
  245.         createWindowString += ",left=" + 
  246.          Math.floor(contentArea.boxObject.screenX + contentArea.boxObject.width / 2 - windowWidth / 2) +
  247.          ",top=" +
  248.          Math.floor(contentArea.boxObject.screenY + contentArea.boxObject.height / 2 - windowHeight / 2);
  249.       } else if (showcasePosition == 1) {
  250.         // Center on current screen
  251.         createWindowString += ",centerscreen=yes";
  252.       } else if (showcasePosition == 2) {
  253.         // Remember last position
  254.         createWindowString += ",left=" + 
  255.          prefs.getIntPref("windowLastX") +
  256.          ",top=" +
  257.          prefs.getIntPref("windowLastY");
  258.       } else if (showcasePosition == 3) {
  259.         // Remember last position relative to invoking window
  260.         createWindowString += ",left=" + 
  261.          (window.screenX + prefs.getIntPref("windowLastRelativeX")) +
  262.          ",top=" +
  263.          (window.screenY + prefs.getIntPref("windowLastRelativeY"));
  264.       } else { // if (showcasePosition == 4) {
  265.         // Center on invoking window
  266.         createWindowString += ",left=" + 
  267.          Math.floor(window.screenX + window.outerWidth / 2 - windowWidth / 2) +
  268.          ",top=" +
  269.          Math.floor(window.screenY + window.outerHeight / 2 - windowHeight / 2);
  270.       }
  271.       // Add "normal" parameters
  272.       createWindowString += ",close=yes,resizable=yes";
  273.       
  274.       var showcaseURL = "chrome://showcase/content/showcase.xul?global=" + allWindows;
  275.       var showcaseWindow = window.openDialog(showcaseURL,
  276.         "showcaseDialog", createWindowString, window);
  277.  
  278.       // Try to focus on new window (will fail if window is modal, but that's not an issue)
  279.       try {
  280.         showcaseWindow.focus();
  281.       } catch (e) {}
  282. }
  283.  
  284.  
  285. function showShowcaseOptions() {
  286.   
  287.   var features;
  288.   try {
  289.     var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  290.                           .getService(Components.interfaces.nsIPrefBranch);
  291.     var instantApply = prefs.getBoolPref("browser.preferences.instantApply");
  292.     features = "chrome,titlebar,toolbar,centerscreen," + (instantApply ? "dialog=no" : "modal,resizable");
  293.   } catch (e) {
  294.     features = "chrome,titlebar,toolbar,centerscreen,modal,resizable";
  295.   }
  296.   openDialog("chrome://showcase/content/settings/settings.xul", "", features);
  297. }
  298.